#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int a[105];
int dp[105][105][105];
int n;
int ans=0;
signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%lld",&t);
	while(t--){
		ans=0;
		memset(dp,0,sizeof(dp));
		scanf("%lld",&n);
		for(int i = 1;i <= n;i++){
			scanf("%lld",&a[i]);
		}
		for(int i = 1;i <= n;i++){
			for(int j = 1;j < i;j++){
				for(int k = 1;k < i;k++){
					if(k==j) continue;
					dp[i+1][i][k]=max(dp[i+1][i][k],dp[i][j][k]+(a[i]==a[j])*a[i]);
					dp[i+1][j][i]=max(dp[i+1][j][i],dp[i][j][k]+(a[i]==a[k])*a[i]);
				}
			}
		}
		for(int i = 0;i <= n;i++){
			for(int j = 0;j <= n;j++){
				ans=max(ans,dp[n+1][i][j]);
			}
		}
		printf("%lld\n",ans);		
	}
	return 0;
}
